/**
 * @param {character[][]} board
 * @return {void} Do not return anything, modify board in-place instead.
 */
var solveSudoku = function(board) {
    function isValid(row, col, val, board) {
        let len = board.length
        // 行不能重复
        for(let i = 0; i < len; i++) {
            if(board[row][i] === val) {
                return false
            }
        }
        // 列不能重复
        for(let i = 0; i < len; i++) {
            if(board[i][col] === val) {
                return false
            }
        }
        let startRow = Math.floor(row / 3) * 3
        let startCol = Math.floor(col / 3) * 3

        for(let i = startRow; i < startRow + 3; i++) {
            for(let j = startCol; j < startCol + 3; j++) {
                if(board[i][j] === val) {
                    return false
                }
            }
        }

        return true
    }
    function recursion(board){
        // 行
        for (let i = 0; i < board.length; i++) {
            // 列
            for (let j = 0; j < board[i].length; j++) {
               
                if(board[i][j] !== '.') continue;

                for (let num = 1; num <= 9; num++) {
                    
                    // 判断当前这个数字,是否符合要求
                    if(isValid(i,j,String(num),board)){
                        board[i][j] = String(num)
                        // 下一层递归
                        let res = recursion(board)
                        if(res) return true

                        board[i][j] = '.'
                    }
                    
                }

                return false
            }
            
        }
        return true
    }

    recursion(board)
};